home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / send.zip / SEND.ASM < prev    next >
Assembly Source File  |  1986-01-02  |  5KB  |  349 lines

  1.     Title    "SEND text"  Copyright (C) 1985 Howard Rumsey 72426,3722 and Barry Simon
  2.     page    132,66
  3.  
  4. Comment *
  5.     SEND acts like a combination of ECHO and PROMPT.  ECHO can be used
  6.     to transmit messages to arbitrary files or devices.  It has several
  7.     disadvantages.  You can't ECHO an escape (ESC) so you can't transmit
  8.     ANSI control sequences to your screen.  ECHO also insists on sending
  9.     a CarriageReturn LineFeed sequence at the end of it's transmission.
  10.     The PROMPT command (DOS2.0 or higher) suffers from none of these 
  11.     defects but it's output can not be redirected.  Also, PROMPT is 
  12.     disabled when "ECHO is off".  SEND combines the best features of both.
  13.     For example the command:
  14.                      send $e[[J$d$_$t
  15.     clears the screen (if you have installed ANSI.SYS), displays the date
  16.     on one line and the time om the next.
  17.  
  18.       SEND has one additional feature.  It allows you to send arbitrary
  19.     control characters.  The standard "^" notation is used.  The line
  20.                      send ^g^[[J
  21.     will ring the bell (^g and ^G are the ASCII BELL) and clear 
  22.     the screen (^[ is ASCII ESC).  The ^ and $ may be freely mixed in
  23.     the command line.  As usual $ can be used to "escape" itself and ^.
  24.     Thus $$ and $^ simply become $ and ^ with no special meaning.
  25. *
  26.  
  27.  
  28. CR    equ    0dh
  29. LF    equ    0ah
  30. BS    equ    08h
  31. ESC    equ    1bh
  32. TAB    equ    09h
  33.  
  34. cseg    segment
  35.     assume    cs:cseg, ds:cseg
  36.  
  37.     org    100h
  38. start:    jmp    send
  39.  
  40. days    db    'Sun',0,'Mon',0,'Tue',0,'Wed',0,'Thu',0,'Fri',0,'Sat',0
  41. d10    dw    10
  42. d100    dw    100
  43.  
  44. send:
  45.     mov    di,81h        ; start of command line
  46.     mov    bl,[di-1]    ; number of characters on command line
  47.     mov    bh,0
  48.     mov    byte ptr [bx+81h],0    ; 0 byte indicates end of line
  49.                     ; this over rides the DOS 'CR'
  50.  
  51. skipspace:            ; skip leading "white spaces"
  52.     call    gch
  53.     jz    exit1
  54.     cmp    al,' '
  55.     jz    skipspace
  56.     cmp    al,TAB
  57.     jz    skipspace
  58.     jmp    s0
  59.  
  60. exit1:    int    20h        ; exit on EOF
  61.  
  62. send1:
  63.     call    gch
  64.     jz    exit1
  65. s0:
  66.     cmp    al,'^'
  67.     jnz    s2
  68.     call    gch
  69.     jnz    s1
  70.     mov    al,'^'        ; send hanging '^'
  71. done:    call    pch
  72.     int    20h
  73. s1:
  74.     and    al,1fh        ; keep the five low order bits
  75. s3:    call    pch
  76.     jmp    send1
  77. s2:
  78.     cmp    al,'$'
  79.     jnz    s3
  80.     call    dodollar
  81.     jmp    send1
  82.  
  83. dodollar:
  84.     call    gch
  85.     jnz    s4
  86.     mov    al,'$'        ; send hanging '$' and exit
  87.     jmp    done
  88.  
  89. s4:
  90.     cmp    al,'t'
  91.     jnz    t0
  92.     mov    ah,2ch        ; Time
  93.     int    21h
  94.     mov    al,ch
  95.     call    p2
  96.     mov    al,':'
  97.     call    pch
  98.     mov    al,cl
  99.     call    p02
  100.     mov    al,':'
  101.     call    pch
  102.     mov    al,dh
  103.     call    p02
  104.     mov    al,'.'
  105.     call    pch
  106.     mov    al,dl
  107.     call    p02
  108.     ret
  109. t0:
  110.     cmp    al,'d'
  111.     jnz    d0
  112.     mov    ah,2ah        ; Date
  113.     int    21h
  114.     mov    ah,0
  115.     mov    si,offset days
  116.     add    ax,ax
  117.     add    ax,ax
  118.     add    si,ax        ; days[4*day]
  119.     call    pstr
  120.     mov    al,' '
  121.     call    pch
  122.     mov    al,dh
  123.     call    p2
  124.     mov    al,'-'
  125.     call    pch
  126.     mov    al,dl
  127.     call    p02
  128.     mov    al,'-'
  129.     call    pch
  130.     mov    ax,cx
  131.     call    ppnum
  132.     ret
  133. d0:
  134.     cmp    al,'p'
  135.     jnz    p0
  136.     call    path        ; Path
  137.     ret
  138. p0:
  139.     cmp    al,'P'
  140.     jnz    pp0
  141.     call    path        ; $P avoids "paths" like C:\\
  142.     cmp    al,0
  143.     jz    pp1
  144.     mov    al,'\'
  145.     call    pch
  146. pp1:    ret
  147. pp0:
  148.     cmp    al,'v'
  149.     jnz    v0
  150.     mov    ah,30h        ; "Version"
  151.     int    21h
  152.     push    ax
  153.     mov    ah,0
  154.     call    ppnum
  155.     mov    al,'.'
  156.     call    pch
  157.     pop    ax
  158.     mov    al,ah
  159.     mov    ah,0
  160.     call    ppnum
  161.     ret
  162. v0:
  163.     cmp    al,'n'
  164.     jnz    n0        
  165.     call    drive        ; Drive
  166.     ret
  167. n0:
  168.     cmp    al,'g'
  169.     jnz    g0
  170.     mov    al,'>'
  171.     call    pch
  172.     ret
  173. g0:
  174.     cmp    al,'l'
  175.     jnz    l0
  176.     mov    al,'<'
  177.     call    pch
  178.     ret
  179. l0:
  180.     cmp    al,'b'
  181.     jnz    b0
  182.     mov    al,'|'
  183.     call    pch
  184.     ret
  185. b0:
  186.     cmp    al,'q'
  187.     jnz    q0
  188.     mov    al,'='
  189.     call    pch
  190.     ret
  191. q0:
  192.     cmp    al,'h'
  193.     jnz    h0
  194.     mov    al,BS
  195.     call    pch
  196.     ret
  197. h0:
  198.     cmp    al,'e'
  199.     jnz    e0
  200.     mov    al,ESC
  201.     call    pch
  202.     ret
  203. e0:
  204.     cmp    al,'_'
  205.     jnz    _0
  206.     mov    al,CR
  207.     call    pch
  208.     mov    al,LF
  209.     call    pch
  210.     ret
  211. _0:
  212.     cmp    al,'M'
  213.     jnz    M00
  214.     mov    ah,2ah        ; Date
  215.     int    21h
  216.     mov    al,dh        ; print two digit month as 'mm'
  217.     call    p02
  218.     ret
  219. M00:
  220.     cmp    al,'D'
  221.     jnz    D00
  222.     mov    ah,2ah        ; Date
  223.     int    21h
  224.     mov    al,dl        ; print two digit day as 'dd'
  225.     call    p02
  226.     ret
  227. D00:
  228.     cmp    al,'Y'
  229.     jnz    Y00
  230.     mov    ah,2ah        ; Date
  231.     int    21h
  232.     mov    ax,cx        ; print year as 'yy'
  233.     mov    dx,0
  234.     div    d100
  235.     mov    ax,dx        ; remainder
  236.     call    p02
  237.     ret
  238. Y00:
  239.     cmp    al,'T'
  240.     jnz    T00
  241.     mov    ah,2ch        ; Time
  242.     int    21h
  243.     mov    al,ch        ; print time as 'hhmm'
  244.     call    p02
  245.     mov    al,cl
  246.     call    p02
  247.     ret
  248. T00:
  249.     call    pch        ; default is send char
  250.     ret
  251.  
  252. path:
  253.     call    drive
  254.     mov    al,':'
  255.     call    pch
  256.     mov    al,'\'
  257.     call    pch
  258.     mov    ah,47h        ; Path
  259.     mov    dl,0        ; default drive
  260.     sub    sp,65        ; room for path name
  261.     mov    si,sp
  262.     int    21h
  263.     call    pstr
  264.     mov    al,[si]
  265.     add    sp,65
  266.     ret
  267.  
  268. drive:
  269.     mov    ah,19h        ; default drive
  270.     int    21h
  271.     add    al,'A'        ; A=0, B=1,...
  272.     call    pch
  273.     ret
  274.  
  275. gch:
  276.     mov    al,[di]
  277.     or    al,al
  278.     jz    gch1
  279.      inc    di
  280. gch1:    ret
  281.  
  282. pch:
  283.     push    ax
  284.     push    dx
  285.     mov    dl,al
  286.     mov    ah,02h
  287.     int    21h
  288.     pop    dx
  289.     pop    ax
  290.     ret
  291.  
  292. pstr:
  293.     push    si
  294. pstr1:    mov    al,[si]
  295.     cmp    al,0
  296.     jz    pstr2
  297.     call    pch
  298.     inc    si
  299.     jmp    pstr1
  300. pstr2:    pop    si
  301.     ret
  302.  
  303. ppnum:                ; print unsigned number
  304.     cmp    ax,0
  305.     jnz    pn0
  306.     call    pdigit
  307.     ret
  308. pn0:
  309.     cmp    ax,d10
  310.     jae    pn1
  311.  
  312. pdigit:
  313.     push    ax
  314.     add    al,'0'
  315.     call    pch
  316.     pop    ax
  317.     ret            
  318. pn1:
  319.     push    dx
  320.     mov    dx,0
  321.     div    d10
  322.     push    dx        ;remainder
  323.     call    pn0
  324.     pop    ax
  325.     call    pdigit
  326.     pop    dx
  327.     ret
  328.  
  329. p02:                ; %02d
  330.     mov    bl,'0'
  331.     jmp    p022        ; %2d
  332. p2:
  333.     mov    bl,' '
  334. p022:
  335.     mov    ah,0
  336.     div    byte ptr d10
  337.     cmp    al,0
  338.     jg    p21
  339.     mov    al,bl
  340.     call    pch
  341.     jmp    p22
  342. p21:    call    pdigit
  343. p22:    mov    al,ah
  344.     call    pdigit
  345.     ret
  346.  
  347. cseg    ends
  348.     end    start
  349.